<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>First Consult</title>
<link href="css/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" charset="utf-8" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js">
</script>
<script type="text/javascript">
function deletePost(index,data){
	document.getElementById(index).disabled = true;
	jQuery.ajax({url:"DoctorQues", type:"post" , data:{data:data}, async:false, success:function(data){
		//alert("Post has been successfully deleted");
	}});
}
function CommentPost(data,index){
	
	var dt=document.getElementById(index).value;
		dt = dt +"$"+ data;
		jQuery.ajax({url:"DocComment", type:"post" , data:{data:dt}, async:false, success:function(data){
		}}); 
}
</script>
</head>

<body id="framebody">
<form id="form1">
 <div id="middlePan">
		<div id="middlebodyPan">
	<jsp:useBean id="DocPost" class="service.ViewDocPosts" scope="session"></jsp:useBean>
	<%String[] posts = DocPost.getDocPost(request.getSession().getAttribute("userid").toString(), request.getSession().getAttribute("doctorid").toString());%>
	<%	String[] postInfo; String[] comments = null; String[] commentInfo = null; %>
	<% if(posts==null){ %>
	<h3>There are no posts posted by you .</h3> 
	<% } else { %>
		<% 
		for( int i=0;i<posts.length;i++ ){ 
			postInfo = posts[i].split("&");
			if(postInfo.length>1){
				comments = postInfo[1].split("\\$");
			}
			else
			{
				comments=null;
			}
			String[] post = postInfo[0].split("%"); 
			String textid = "text" + i;
		%>
	<div style="background-color: #EFEDD8; margin-top: 10px;" >
	<table style="width:100%;padding:17px;">
		<tr> <td><b> <%=post[1] %> </b>	</td> <td> <input type="submit" id="<%=i%>" name="delete" value="Delete"  onclick="deletePost('<%=i%>','<%=post[5]%>')"> </td> </tr>
		
		<tr> <td>	&nbsp;&nbsp;&nbsp;<%=post[2] %>
		<tr> <td>	<b>For</b> &nbsp;&nbsp;&nbsp;<%=post[0] %>
		
	<b>on</b>	&nbsp;&nbsp;&nbsp;<%=post[6]%> </td></tr>
			<%if(comments!=null) { %>
			<% if(comments.length>=1) %>
			<tr><td> <b>Comments:</b></td></tr>
		<% for( int j=0; j<comments.length; j++ ){ %>	
		<% commentInfo = comments[j].split("%"); %>	
		<tr><td><%=j+1 %>.)&nbsp;&nbsp;<%=commentInfo[1]%>&nbsp;&nbsp;<b>by</b>&nbsp;&nbsp;<%=commentInfo[2] %>&nbsp;&nbsp;<br><b>on</b>&nbsp;&nbsp;<%=commentInfo[3] %></td></tr>
		<% } %>
		<% } %>
		<tr> <td><textarea rows="2" required id="<%=textid%>" name="comment"  style="width: 349px; height: 39px;resize:none;" onclick="hi()">
		</textarea> </td><td><input type="submit" id="<%=i%>" name="cmt" value="Comment"  onclick="CommentPost('<%=post[5]%>','<%=textid%>')"> 
		</td></tr>	
	</table>
	</div>
	<% } %>
	<% } %>
</div>		 	     
</div>	  	
</form>	
</body>
</html>